package com.xuecheng.learning.controller;

import com.xuecheng.commons.model.dto.LearningProgressDto;
import com.xuecheng.commons.model.vo.CourseRecordVo;
import com.xuecheng.commons.model.vo.ResourceVo;
import com.xuecheng.commons.model.vo.ResponseResult;
import com.xuecheng.learning.service.CourseRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 选课记录前端控制器
 */
@Slf4j
@RestController
public class CourseRecordController {

    @Autowired
    private CourseRecordService  courseRecordService;

    /**
     * 查询学生对课程的选课记录信息
     * GET： /learnedRecords/myCourseRec/{coursePubId}
     * 参数：coursePubId
     * 返回值：ResponseResult<CourseRecordVo>
     */
    @GetMapping("/learnedRecords/myCourseRec/{coursePubId}")
    public ResponseResult<CourseRecordVo> findRecordByPubId(
                    @PathVariable("coursePubId") Long coursePubId) {
        return courseRecordService.findRecordByPubId(coursePubId);
    }

    /**
     * 查询课程的媒资信息
     * GET /learnedRecords/resource-url
     * 参数：Query参数
     *    coursePubId，mediaId，teachplanId
     * 返回：ResponseResult<ResourceVo>
     */
    @GetMapping("/learnedRecords/resource-url")
    public ResponseResult<ResourceVo> findPlayUrl(Long coursePubId,Long mediaId,Long teachplanId) {
        return courseRecordService.findPlayUrl(coursePubId,mediaId,teachplanId);
    }

    /**
     * 保存学习进度
     * POST  /learnedRecords/progress
     * 请求参数：LearningProgressDto
     * 响应 ResponseResult
     */
    @PostMapping("/learnedRecords/progress")
    public ResponseResult progress(@RequestBody LearningProgressDto dto) {
        return courseRecordService.progress(dto);
    }
    @GetMapping("project/57/interface/api/1345")
    public ResponseResult findSelectCourse(@RequestParam("id") String id){
        return courseRecordService.findSelectCourse(id);
    }
}
